package common

import (
	"crypto/hmac"
	"crypto/md5"
	"crypto/sha1"
	"encoding/hex"
	"github.com/satori/go.uuid"
)

func Sha1(data string) string {
	obj := sha1.New()
	obj.Write([]byte(data))
	return hex.EncodeToString(obj.Sum([]byte("")))
}

func Hmac(key, data string) string {
	obj := hmac.New(md5.New, []byte(key))
	obj.Write([]byte(data))
	return hex.EncodeToString(obj.Sum([]byte("")))
}

func Md5(data string) string {
	obj := md5.New()
	obj.Write([]byte(data))
	return hex.EncodeToString(obj.Sum([]byte("")))
}

func NewUUID() string {
	// 创建可以进行错误处理的 UUID v4
	return uuid.NewV4().String()
}